#pragma once
#include <GL/gl.h>
#include "GraphicsFile.h"


//+------------------------------------------------------------------+
namespace align
{
	enum h	{	left, right, centered	};
	enum v	{	top, bottom, center		};
};



//+==================================================================+
class Texture
{
	GLuint	texture,
				width,
				height;
public:
//////////////////////////////////////////////////////////////////////

//+------------------------------------------------------------------+
	Texture(LPCTSTR filename = NULL);
	Texture(const GraphicsFile &g);
	~Texture();

//+------------------------------------------------------------------+
//	Upload data to graphics card.
	void		setData(const GraphicsFile &);
	void		setData(GLsizei w, GLsizei h, GLenum format = 0, const BYTE *data = NULL);
	void		setEmpty()						{	width = height = 0;	}
//	void		setTexture(GLuint t)			{	texture = t;			}
	GLuint	getTexture()	const			{	return texture;		}
	GLuint	getWidth()		const			{	return width;			}
	GLuint	getHeight()		const			{	return height;			}

//+------------------------------------------------------------------+
	void bind(GLenum target = GL_TEXTURE_2D) const
	{
		glBindTexture(target, texture);
	}

//+------------------------------------------------------------------+
//	Draw the texture as a rectangle.
	void draw(const RECT &) const;

//+------------------------------------------------------------------+
//	Draw the texture as a rectangle, with the upper left corner
//	or the center at the point(x,y), depending on "centered".
	void draw(float x = 0, float y = 0, float scale = 1.0f, bool centered = false) const;

};//class Texture




//+==================================================================+
//	Basically an array of textures, in one graphics file.
//	Usually corresponding to to a linear subset of character codes.
class TiledTexture
{
	const		Texture t;						// texture with all characters
	wchar_t	char0;							// value of the first character in the texture
	unsigned	charCount;						// number of characters in the texture: must be equally spaced over the width
	unsigned	rows;								// number of rows in the texture
	float		dx;								// distance between chars in pixel
	float		du,dv;							// distance between normalizd texture coordinates

public:
//////////////////////////////////////////////////////////////////////
	TiledTexture(LPCTSTR filename,		wchar_t firstChar = L'0', unsigned numChars = 10, unsigned numRows = 1, float kerning = 1.0f);
	TiledTexture(const GraphicsFile &g,	wchar_t firstChar = L'0', unsigned numChars = 10, unsigned numRows = 1, float kerning = 1.0f);

//+------------------------------------------------------------------+
	void drawString	(const std::wstring &str,	float x = 0, float y = 0, float scale = 1.0f, align::h hAlign = align::left,  align::v vAlign = align::top) const;
	void drawNumber	(int n,							float x = 0, float y = 0, float scale = 1.0f, align::h hAlign = align::right, align::v vAlign = align::top, bool sign = false, unsigned minDigits = 0) const;
	void draw			(wchar_t c, float x = 0, float y = 0, float scale = 1.0f, bool centered = false) const;

	unsigned getCharCount()	const	{	return charCount;			}
	unsigned getWidth()		const	{	return t.getWidth();		}
	unsigned getHeight()		const	{	return t.getHeight();	}

	GLuint	getTexture()	const	{	return t.getTexture();	}
	void		setRows(unsigned n)	{	rows = n; dv = 1.0f/n;	}

};//class TiledTexture
